
require "TSLib"
init(0)
w,h = getScreenSize()


UINew("菜呱激斗","运行脚本","退出脚本","uiconfig.dat",0,0,w*0.9,h*0.9,"255,231,186","255,231,186","","tab",1,15,"right") --方式一，宽高为屏幕的 90%

UIRadio("rdo","小牛奶,大冒险敲石块,基因试炼点击","0",-1,0,"",1,1)
UIShow()

if rdo == "小牛奶" then--返回值为字符型
    

    
    build_spacing = 100;-- x y  通用
    build_color = 0x459656;
    exec_count = 0;  -- 执行计数
    graden = 0; -- 分数
    
    
    tap_left_x = 199;
    tap_left_y = 870;
    tap_right_x = 559;
    tap_right_y = 870;
    
    
    obstacle_color = 0x579b3b; -- 障碍物
    obstacle_spacing_y = 75;  -- 障碍物间距
    obstacle_spacing_x = 0;
    
    w,h = getScreenSize();
    x= -1;
    y= -1;
    original_color = 0x459656; -- 源点
    enable_exit = false
    
    
    
    
    -- left --right
    function search_path(x,y,last_path) 
        local lx = x-build_spacing;
        local ly = y-build_spacing;
        local rx = x+build_spacing;
        local ry = y-build_spacing;
    
    
        if x < 200 or y < 200 then
            return -1;
        end
    
        if isColor(lx,ly,build_color) == true and (isColor(lx, ly-obstacle_spacing_y, obstacle_color,85) == false) then
            
    
            return 0;
        end
    
        if isColor(rx,ry,build_color) == true and (isColor(rx-23, ry-80, obstacle_color,85) == false) then
            return 1;
        end
    
            return -1;
    
        
    end
    
    
    function loop_exec_script() 
    
    
        exec_path = {}; -- 路径 0 left , 1 right, -1 无路可走
        x =   370;  
        y =  770;
    
        while isColor(x,y,original_color) == false do
        end
    
    
        while true do
            exec_res = -1;
            exec_res = search_path(x,y,nil);
            if exec_res == 1 then
                x = x + build_spacing;
                y = y - build_spacing;
                
            elseif exec_res == 0 then
                x = x - build_spacing;
                y = y - build_spacing;
            
            else
                if graden >= 5000 then
                    enable_exit = true
                end 
                break
            end;
            table.insert(exec_path, exec_res);
            exec_count=exec_count+1
        end
    
    
        for i, v in ipairs(exec_path) do
            if v == 0 then
                tap(tap_left_x,tap_left_y);
            elseif v == 1 then
                tap(tap_right_x,tap_right_y);
            end
        end 
        x= 540;
        y=1150;
    
    
    end
    
    
    
    while true do
        loop_exec_script()
        mSleep(500)
    end

    elseif rdo == "大冒险敲石块" then

        while isColor( 352,  648, 0x7d9e3b ) == true do
            tap(116,  434,0);
        end
        
        while isColor( 352,  648, 0x7d9e3b ) == false do
        end
        
        tap(116,  434,0);
        tap(244,  361,0);
        tap( 360,  308,0);
        tap( 474,  379,0);
        tap(356,  450,0);
        tap( 234,  508,0);
        tap(126,  590,0);
        tap(592,  454,0);
        tap(476,  526,0);
        tap(117,  731,0);
        tap(363,  599,0);
        tap( 236,  672,0);
        tap(592,  608,0);
        tap(469,  678,0);
        tap(365,  746,0);
        tap(234,  830,0);
        tap(146,  889,0);
        tap(365,  746,0);
        tap(594,  759,0);
        tap(514,  807,0);
        tap( 339,  895,0);
        tap( 269,  973,0);
        tap( 605,  903,0);
        tap(500,  960,0);
        tap( 373, 1037,0);  
        

    elseif rdo == "基因试炼点击" then
        while isColor( 544,  506, 0xfd5000 ) == false do
            tap( 359, 1090,0)
        end
        
end
